//
//  XQCalendarTool.swift
//  Spark Peso
//
//  Created by 小琦 on 2025/2/9.
//

import UIKit

class XQCalendarTool: NSObject {

    class func getYearDataSourceWithMinYear() -> [String] {
        let minYear = 1940
        let currentCalendar = Calendar.current
        let nowYear = currentCalendar.component(.year, from: Date())
        
        var yearList : [String] = []
        
        for y in minYear...nowYear {
            yearList.append("\(y)")
        }
        return yearList
    }
    
    class func getMonthDataSource() -> [String]{
        var numbers: [String] = []
            for number in 1...12 {
                numbers.append(String(format: "%02d", number))
            }
            return numbers
    }
    
    class func getMonthWithIndex(index : Int) -> String {
        if (index - 1 < getMonthDataSource().count) {
            return getMonthDataSource()[index - 1]
        }
        return ""
    }
    
    class func getDay(year : Int,month : Int) -> [String] {
        let currentCalendar = Calendar.current
        
        var components = DateComponents()
        components.year = year
        components.month = month
        components.day = 1
        
        guard let firstDayOfMonth = currentCalendar.date(from: components) else {
            return []
        }
        let range = currentCalendar.range(of: .day, in: .month, for: firstDayOfMonth)
            
        var daysArray: [String] = []
        
        for day in range!.lowerBound..<range!.upperBound {
           daysArray.append("\(day)")
        }
       
        return daysArray
    }
}
